﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); 
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Int32 N = Convert.ToInt32(textBox2.Text);    
            Random R = new Random();                       
            Form[] b = new Form[N];                
            for (Int32 i = 0; i < N; i++)
            {
                b[i] = new Form();                        
               b[i].Show();                      
                b[i].Name = "окно" + Convert.ToString(i);  
                b[i].Text = b[i].Name;                    
                b[i].Location = new Point(R.Next(200, 400), R.Next(50, 400)); 
               b[i].Click += new EventHandler(My_Click); 
            }
        }

        private void My_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Привет, я " + ((Button)sender).Name + "\nИ это мой обработчик");
        }

        private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
